package com.power.dao.impl;

import com.power.dao.NeedDealtDao;
import com.power.utils.JdbcBuild;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/05 10:34
 * Description:
 * Version: V1.0
 */
public class NeedDealtDaoImpl extends JdbcBuild implements NeedDealtDao {

    @Override
    public List<Map<String, Object>> findNeedDealtById(String user_account, String role_id, int newPage, int newLimit) throws SQLException {
        String sql=null;
        System.out.println("role_id"+role_id);
        //3为巡检，4消缺
        if (role_id.equals("3")){
            sql ="select *  from inspection,line,users where inspection.inspection_account=? and task_state=5 AND inspection.line_id=line.line_number  and inspection.lineman_account=users.user_account limit ?,?";
        }else if (role_id.equals("4")){
            sql ="select * from sovle,users,defect_details,line where  defect_details.line_id=line.line_number and sovle_account=? and sovle_state=5 AND sovle.user_id=users.user_account and sovle.defect_details_id=defect_details.defect_details_id limit ?,?";
        }
        Object[] objects={user_account,(newPage-1)*newLimit,newLimit};
        List<Map<String,Object>> list=super.findAllForList(sql,objects);
        return list;
    }

    @Override
    public int NeedDeadltCount(String user_account, String role_id) throws SQLException {
        //3为巡检，4消缺
        String sql=null;
        if (role_id.equals("3")){
            sql ="select count(*) from inspection where inspection_account=? and task_state=5";
        }else if (role_id.equals("4")){
            sql ="select count(*) from sovle where sovle_account=? and sovle_state=5";
        }
       Object[] objects={user_account};
        int count=super.findAllForInt(sql,objects);
        return count;
    }

    @Override
    public int needDealtUpdate(String user_account, String role_id,String task_id) throws SQLException {
        //3为巡检，4消缺
        String sql=null;
        if (role_id.equals("3")){
            sql ="update  inspection set task_state=6 where inspection_account=? and task_id=?";
        }else if (role_id.equals("4")){
            sql ="update sovle set sovle_state=6 where sovle_account=? and sovle_id=?";
        }
        Object[] objects={user_account,task_id};
        int res=super.executeUpdate(sql,objects);
        return res;
    }
}
